/*
 * Modbus mutex for RTU.
 * Copyright (c) 2012  apleilx
 * All rights reserved.
 * no limite
 */

/* ----------------------- Platform includes --------------------------------*/

#include "os_obj.h"
#include "mbdef.h"

#if MB_OS_USED > 0

//如果每个对象只在单一的任务中操作，无需互斥锁

//static osMutexId     MutexObjmbCmd;
//static uint8_t       mbMutexCreated = 0;

//osMutexDef(MBCMD_Mutex);

/*****************************************************************************//*!
*
* @brief   modbus sync mutex creat.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void mbOsSyncMutexCreat(void)
{

//    if(!mbMutexCreated)
//        MutexObjmbCmd = osMutexCreate (MutexObjmbCmd);
//
//    mbMutexCreated = 1;
}

/*****************************************************************************//*!
*
* @brief   modbus sync mutex pend.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void mbOsSyncMutexPend(void)
{
    //OSMutexPend (&MutexObjmbCmd, 0,  OS_OPT_PEND_BLOCKING, &cpu_ts, &os_err);
//    osMutexWait(MutexObjmbCmd,1000);
}

/*****************************************************************************//*!
*
* @brief   modbus sync mutex post.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void mbOsSyncMutexPost(void)
{

    //OSMutexPost (&MutexObjmbCmd,  OS_OPT_POST_NO_SCHED, &os_err);
//    osMutexRelease(MutexObjmbCmd);
}

#endif

/*****************************************************************************//*!
*
* @brief   modbus os delay.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void mb_os_delay(uint32_t ms)
{
    osDelay(ms_ticks(ms));
}


/*****************************************************************************//*!
*
* @brief   modbus event snd.
*
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void mb_os_send(uint16_t event)
{
    osSignalSet(osobj.tid_Modbus, event);
}
